package api

import (
	"gitee.com/ling1314/origin-utility/constant"
	"gitee.com/ling1314/origin-utility/modules/service"
	"github.com/gin-gonic/gin"
)

type hostApi struct{}

func (api hostApi) Page(c *gin.Context) {
	result, err := service.HostService.Page()
	if err != nil {
		BadWithCode(c, constant.ErrorUnknown)
		return
	}
	Ok(c, result)
}

func (api hostApi) Details(c *gin.Context) {
	input := struct {
		Id int64 `uri:"id,string"`
	}{}
	if err := c.ShouldBindUri(&input); err != nil {
		BadWithCode(c, constant.ParamsError)
		return
	}
	rs, err := service.HostService.Details(input.Id)
	if err != nil {
		BadWithError(c, err)
		return
	}
	Ok(c, rs)
}

func (api hostApi) List(c *gin.Context) {
	rs, err := service.HostService.List()
	if err != nil {
		BadWithError(c, err)
		return
	}
	Ok(c, rs)
}
